@include('admin::layouts.header')
<div class="admin-main layui-anim layui-anim-upbit">
	<fieldset class="layui-elem-field layui-field-title">
		<legend>编辑</legend>  
	</fieldset>
	<form class="layui-form layui-form-pane" lay-filter="form">
		<div class="layui-form-item">
            <label class="layui-form-label">商品分类</label>
            <div class="layui-input-4">
                <input type="text" value="{{$info['type_title']}}" disabled class="layui-input">
            </div>
        </div>
		<div class="layui-form-item">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-4">
                <input type="text" maxlength="50" name="name" lay-verify="required" placeholder="请输入商品名称" value="{{$info['name']}}"  class="layui-input">
            </div>
        </div>
		@include('admin::layouts.edit_html_image',['name'=>'图片','adPic'=>'adPic','image_id'=>'image_id','adBtn'=>'adBtn','adPic_val'=> $info['image_one']['url'],'image_id_val'=>$info['image_id']])
		
		@include('admin::layouts.edit_html_image_all',['name'=>'轮播图','upload_img'=>'upload_img','upload_img_list'=>'upload_img_list','images'=>$images])

		
		@if($info['specs_status'] == 0)
			<div class="layui-form-item">
				<label class="layui-form-label">产品售价</label>
				<div class="layui-input-4">
					<input type="text" maxlength="10" id="money" value="{{$info['product_spec_to'][0]['money']}}" placeholder="请输入产品售价" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">产品市场价</label>
				<div class="layui-input-4">
					<input type="text" maxlength="10" id="bazaar_money" value="{{$info['product_spec_to'][0]['bazaar_money']}}" placeholder="请输入产品市场价" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">产品成本价</label>
				<div class="layui-input-4">
					<input type="text" maxlength="10" id="cost_money" value="{{$info['product_spec_to'][0]['cost_money']}}" placeholder="请输入产品成本价" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">邮费</label>
				<div class="layui-input-4">
					<input type="text" maxlength="10" id="postage" value="{{$info['product_spec_to'][0]['postage']}}" placeholder="请输入邮费" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">库存</label>
				<div class="layui-input-4">
					<input type="text" maxlength="10" id="stock" value="{{$info['product_spec_to'][0]['stock']}}" placeholder="请输入库存" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">销量</label>
				<div class="layui-input-4">
					<input type="text" maxlength="10" id="sales" value="{{$info['product_spec_to'][0]['sales']}}" placeholder="请输入销量" class="layui-input">
				</div>
			</div>
		@else
			<div id="sku_list_info">
				<table cellspacing="0" cellpadding="0" border="0" class="layui-table">
					<tbody>
						<tr data-index="0" class="">
							@foreach($attrbute_list as $key=>$value)
								<td align="center">
									<div class="layui-table-cell laytable-cell-1-0-0">{{$value}}</div>
								</td>
							@endforeach
							<td align="center">
								<div class="layui-table-cell laytable-cell-1-0-0">产品售价</div>
							</td>
							<td align="center">
								<div class="layui-table-cell laytable-cell-1-0-0">产品市场价</div>
							</td>
							<td align="center">
								<div class="layui-table-cell laytable-cell-1-0-0">产品成本价</div>
							</td>
							<td align="center">
								<div class="layui-table-cell laytable-cell-1-0-0">邮费</div>
							</td>
							<td align="center">
								<div class="layui-table-cell laytable-cell-1-0-0">库存</div>
							</td>
							<td align="center">
								<div class="layui-table-cell laytable-cell-1-0-0">销量</div>
							</td>
						</tr>
						@foreach($info['product_spec_to'] as $key1=>$value1)
							<tr class="from_item_id">
								@foreach($value1['specs'] as $key2=>$value2)
									<td align="center">
										<div class="layui-table-cell laytable-cell-1-0-0" data-id="{{$value2['id']}}">{{$value2['value']}}</div>
									</td>
								@endforeach
								<td align="center">
									<div class="layui-table-cell laytable-cell-1-0-6">
										<input class="list_order layui-input" size="10" value="{{$value1['money']}}">
									</div>
								</td>
								<td align="center">
									<div class="layui-table-cell laytable-cell-1-0-6">
										<input class="list_order layui-input" size="10" value="{{$value1['bazaar_money']}}">
									</div>
								</td>
								<td align="center">
									<div class="layui-table-cell laytable-cell-1-0-6">
										<input class="list_order layui-input" size="10" value="{{$value1['cost_money']}}">
									</div>
								</td>
								<td align="center">
									<div class="layui-table-cell laytable-cell-1-0-6">
										<input class="list_order layui-input" size="10" value="{{$value1['postage']}}">
									</div>
								</td>
								<td align="center">
									<div class="layui-table-cell laytable-cell-1-0-6">
										<input class="list_order layui-input" size="10" value="{{$value1['stock']}}">
									</div>
								</td>
								<td align="center">
									<div class="layui-table-cell laytable-cell-1-0-6">
										<input class="list_order layui-input" size="10" value="{{$value1['sales']}}" data-id="{{$value1['id']}}">
									</div>
								</td>
							</tr>
						@endforeach
					</tbody>
				</table>
			</div>	
		@endif	
		
		
		
		@include('admin::layouts.edit_ue',['name'=>'文章内容','id'=>'content','value'=>$info['content']])
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-2">
                <input type="text" onkeyup="this.value=this.value.replace(/\D/gi,&quot;&quot;)" maxlength="11" name="sort" value="{{$info['sort']}}" placeholder="请输入排序编号" lay-verify="required" class="layui-input">
            </div>
        </div>
		@include('admin::layouts.submit',['url'=>route('shop_admin.product.index')])
	</form>
</div>
@include('admin::layouts.footer')
@include('admin::layouts.edit_ajax_image',['url'=>route('admin.upload.upload_file'),'adPic'=>'#adPic','image_id'=>'#image_id','adBtn'=>'#adBtn'])



@include('admin::layouts.edit_ajax_image_all',['url'=>route('admin.upload.upload_file'),'upload_img'=>'#upload_img','upload_img_list'=>'#upload_img_list','images'=>'images'])

<script>
	layui.use(['form','layer'], function () {
		var form = layui.form,layer = layui.layer,$= layui.jquery;
		form.verify({	
			image_id: function(value){  
				if(value == ''){  
					return '请上传图片！';  
				}  
			}	
		});
		//提交监听
		form.on('submit(submit)', function (data) {
			var specs_status = "{{$info['specs_status']}}";
			var specs_data = [];
			var attrbute_list_count = Number("{{$attrbute_list_count}}");
			if(specs_status == 1){
				$('.from_item_id').each(function(){
					var money,bazaar_money,cost_money,postage,stock,sales,id;
					$(this).children().each(function(){
						if($(this).index() == attrbute_list_count){
							money = $(this).children('div').children('input').val();
						}
						if($(this).index() == attrbute_list_count + 1){
							bazaar_money = $(this).children('div').children('input').val();
						}
						if($(this).index() == attrbute_list_count + 2){
							cost_money = $(this).children('div').children('input').val();
						}
						if($(this).index() == attrbute_list_count + 3){
							postage = $(this).children('div').children('input').val();
						}
						if($(this).index() == attrbute_list_count + 4){
							stock = $(this).children('div').children('input').val();
						}
						if($(this).index() == attrbute_list_count + 5){
							sales = $(this).children('div').children('input').val();
							id = $(this).children('div').children('input').attr('data-id');
						}
					})
					specs_data.push({
						money:money,
						bazaar_money:bazaar_money,
						cost_money:cost_money,
						postage:postage,
						stock:stock,
						sales:sales,
						id:id,
					})
				})
			}else{ 
				specs_data.push({
						money:$('#money').val(),
						bazaar_money:$('#bazaar_money').val(),
						cost_money:$('#cost_money').val(),
						postage:$('#postage').val(),
						stock:$('#stock').val(),
						sales:$('#sales').val(),
						id:"{{$info['product_spec_to'][0]['id']}}",
				})
			} 
			data.field.specs_data = specs_data;
			loading =layer.load(1, {shade: [0.1,'#fff']});
			data.field._method = 'PUT';
			$.post("{{route('shop_admin.product.update',['id'=>$info['id']])}}",data.field,function(res){ 
				layer.close(loading);
				if(res.status == 1){
					layer.msg(res.msg,{icon: 1, time: 1000},function(){
						location.href = res.url;
					});
				}else{
					layer.msg(res.error,{icon: 2, time: 1000});
				}
			});
		})

	});
</script>




















